﻿using CoreShop.Library;
using CoreShop.Model;
using SqlSugar.Extensions;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace CoreShop.App
{
    public partial class UIScaleDetailItem : UIUserControl
    {
        public UIScaleDetailItem()
        {
            InitializeComponent();
        }

        public corecmsscale Info { get; set; }
        public UIScaleDetailItem(corecmsscale info)
        {
            InitializeComponent();
            Info = info;
            var scaleTypes = EnumHelper.EnumToList<GlobalEnumVars.ScaleBarcodeType>();
            cbmScaleType.DataSource = scaleTypes;
            cbmScaleType.DisplayMember = "description";
            cbmScaleType.ValueMember = "value";
            this.txtName.Text = this.Info.name;
            this.cbmScaleType.SelectedValue = this.Info.scaleType;
            this.ipAddress.Text = this.Info.ipAddress;
            this.selectFlag.Checked = this.Info.selectFlag;            
        }

        public corecmsscale GetModelValue()
        {
            this.Info.name = this.txtName.Text;
            this.Info.scaleType = this.cbmScaleType.SelectedValue.ObjToInt(0);
            this.Info.ipAddress = this.ipAddress.Text;
            this.Info.selectFlag = this.selectFlag.Checked;
            return this.Info;
        }

        public bool Checked
        {
            get => selectFlag.Checked;
            set => selectFlag.Checked = value;
        }

        public event EventHandler DeleteInfo;
        private void btnDelete_Click(object sender, EventArgs e)
        {
            DeleteInfo?.Invoke(this, e);
        }
    }
}
